#!/bin/env python
#coding:utf-8
__author__ = 'jieli'

from django.db import models
from django.contrib.auth.models import (
    BaseUserManager, AbstractBaseUser,Group,PermissionsMixin
)
import django

class UserManager(BaseUserManager):
    def _create_user(self, name, email, password,
                     is_staff, is_admin, is_superuser):
        """
        Creates and saves a User with the given username, email and password.
        """
        #now = timezone.now()
        print ('name value:',name)
        print ('email value:', email)
        print ('password value:', password)
        print ('is_staff value:', is_staff)
        print ('is_admin value:', is_admin)
        print ('is_superuser value:', is_superuser)

        if not name:
            raise ValueError('The given name must be set')
        email = self.normalize_email(email)
        user = self.model(name=name, email=email,
                          is_staff=is_staff, is_active=True,
                          is_admin=is_admin )
        user.set_password(password)
        user.save(using=self._db)
        return user

    def create_user(self, name, email=None, password=None, **extra_fields):
        return self._create_user(name, email, password, False, False, False)

    def create_superuser(self, name, email, password, **extra_fields):
        return self._create_user(name, email, password, True, True, True)

